#include <vector>
#include <unordered_map>
using namespace std;
/*
 * @lc app=leetcode.cn id=133 lang=cpp
 *
 * [133] 克隆图
 */
class Node {
public:
    int val;
    vector<Node*> neighbors;
    Node() {
        val = 0;
        neighbors = vector<Node*>();
    }
    Node(int _val) {
        val = _val;
        neighbors = vector<Node*>();
    }
    Node(int _val, vector<Node*> _neighbors) {
        val = _val;
        neighbors = _neighbors;
    }
};

// @lc code=start
/*
// Definition for a Node.

*/

class Solution {
public:
    unordered_map<Node*, Node*> mapper;
    Node* cloneGraph(Node* node) {
        if (!node) return nullptr;
        if (mapper.count(node)) {
            return mapper[node];
        }
        Node* cpy = new Node(node->val);
        mapper.insert({node, cpy});
        for (auto x: node->neighbors) {
            cpy->neighbors.push_back(cloneGraph(x));
        }
        return cpy;
    }
};
// @lc code=end

